﻿/*-----------------------------------------------
// File: BattleRunningState.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Battle.View
{

    public class BattleRunningState : Fsm.FsmStateMonoBase<BattleState> 
    {
        public BattleViewCtrl viewCtrl;
        public BattleRunningState(BattleState state, BattleViewCtrl ctrl) : base(state, ctrl)
        {
            viewCtrl = ctrl;
            InitBattleRoundCtrl();
        }

        protected virtual void InitBattleRoundCtrl() {
            battleRoundCtrl = new BattleRoundCtrl(this);
        }

        public BattleRoundCtrl battleRoundCtrl = null;
        public override void Enter()
        {
            Debug.Log("Enter BattleRunningState");
            viewCtrl.curRunningCamp = viewCtrl.initRunCamp;
            battleRoundCtrl.SwitchState(BattleRoundState.ShowCampRunState);
        }

        public override void Update()
        {
            if (BattleViewCtrl.GetInstance().isCanBattleOver && BattleManager.Instance.isSkip) {
               BattleManager.Instance.FightOver();
                return;
            }
            if (battleRoundCtrl != null)
                battleRoundCtrl.UpdateState();
            ViewRespectCtrl.GetInstance().Tick();
        }

        public override void Leave()
        {
        }

        public Fsm.IFsmState<BattleRoundState> GetCurrentState() {
            return battleRoundCtrl.GetCurrentState();
        }

        public T GetCurrentState<T>() {
            var s = battleRoundCtrl.GetCurrentState();
            if (s.GetType() == typeof(T))
                return (T)s;
            else
                return default(T);
        }
        public BattleRoundState GetCurrentStateType() {
            return battleRoundCtrl.GetCurrentStateType();
        }

        public void SwitchState(BattleRoundState nextState) {
            battleRoundCtrl.SwitchState(nextState);
        }

        public void TransBegin()
        {
            battleRoundCtrl.SwitchState(BattleRoundState.FormationTransferState);
        }

        public void TransEnd()
        {
            battleRoundCtrl.SwitchState(BattleRoundState.RoundWaitState);
        }

        public void AddOnceAttackCache(OnceAttackPackageBase package)
        {
            battleRoundCtrl.AddUltimateCache(package);
        }


    }
}
